<template>
  <view class="house">
    <life-empty v-if='!houseList.length' url='/pkg-house/add-house/add-house' text="您还没有认证房屋，请点击"></life-empty>
    <view v-else class="house-item">
      <house-item @help='onhelp' @click='goDetail' :data-id="item.id" v-for="item in houseList" :key="item.id"
        :list='item' @delclick="onclick">
      </house-item>
      <u-modal :show="show" showCancelButton @cancel="cancel" @confirm="confirm" ref="uModal" title="是否删除已绑定房屋？"
        :asyncClose="true">
      </u-modal>
      <life-button icon="../../static/icon/add.png" @click='goadd'>添加新房屋</life-button>
    </view>
    <!-- 修改状态 -->
    <u-action-sheet :actions="list" title="修改状态" :show="show1" closeOnClickOverlay @close="close" @select="select">
    </u-action-sheet>
  </view>
</template>

<script>
  import {
    getHouseList,
    deleteRoom,
    updateStatus
  } from '../../api/house.js'
  export default {
    data() {
      return {
        houseList: [],
        show: false,
        id: null,
        // 弹出
        show1: false,
        list: [{
            name: '审核中',
            id: "1"
          },
          {
            name: '审核成功',
            id: "2"
          },
          {
            name: '审核失败',
            id: "3"
          }
        ],
        query: {}
      }
    },
    onLoad() {
      this.getHouseList()
    },
    methods: {
      // 点击
      async select(e) {
        console.log(e)
        this.query.status = e.id
        const res = await updateStatus(this.query.type, this.query.id, this.query.status)
        this.getHouseList()
      },
      // 关闭
      close() {
        this.show1 = false
      },
      // 点击修改状态
      onhelp(status, id) {

        this.query = {
          status: "",
          id,
          type: "room"
        }
        this.show1 = true

      },
      async getHouseList() {
        const res = await getHouseList()
        this.houseList = res.data
        // console.log(this.houseList)
      },
      goadd() {
        uni.navigateTo({
          url: '/pkg-house/add-house/add-house'
        })
      },
      onclick(id) {
        // console.log(id)
        this.show = true
        this.id = id

      },
      async confirm() {
        try {
          await deleteRoom(this.id)
          this.show = false
          this.getHouseList()
        } catch (e) {
          console.log(e)
        }
      },
      cancel() {
        this.show = false
      },
      goDetail(id) {
        // console.log(id,)
        uni.navigateTo({
          url: '/pkg-house/house-details/house-details?id=' + id
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .house {
    height: 100%;
    background-color: #FAFAFA;
  }

  .house-item {
    padding: 40rpx;
    padding-bottom: 300rpx;
  }
</style>
